package com.ddd.demo.lee.单调栈;

import java.util.Stack;

public class 单调递减栈 {

    private Stack<Integer> stack;

    public 单调递减栈() {
        stack = new Stack<>();
    }

    public void push(int val) {
        while (!stack.isEmpty() && val >= stack.peek()) {
            stack.pop();
        }
        stack.push(val);
    }

    public int pop() {
        if (!stack.isEmpty()) {
            return stack.pop();
        } else {
            return -1;
        }
    }

    public int top() {
        if (!stack.isEmpty()) {
            return stack.peek();
        } else {
            return -1;
        }
    }

    public boolean isEmpty() {
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        单调递减栈 单调递减栈 = new 单调递减栈();
        单调递减栈.push(1);
        单调递减栈.push(3);
        单调递减栈.push(2);
        单调递减栈.push(4);

        System.out.println(单调递减栈.pop());
        System.out.println(单调递减栈.top());
        System.out.println(单调递减栈.isEmpty());
    }
    
}
